'use strict'

//登录判断
let users = async(ctx,next)=>{
    //获取账户
    let username = ctx.request.body.username || '';
    //获取密码
    let password = ctx.request.body.password || '';

    if(username == 'admin' && password == '123'){
        // 如果账号和密码正确,则跳转到登录成功界面
        ctx.response.redirect('/login/red');
    }else{
        // 账号或密码有误,都跳转到登录失败界面
        ctx.response.redirect('/login/green');
    }
}

//登录成功
let red_fn = async(ctx,next)=>{
    ctx.body = '登录成功'
}

//登录失败
let green_fn = async(ctx,next)=>{
    ctx.body = '登录失败'
}

// 暴露出去
module.exports={
    '/login':['post',users],
    '/login/red':['get',red_fn],
    '/login/green':['get',green_fn],
}